package com.zhuozhou.jdyc.api;

import android.app.Application;

/**
 * Created by 方舟 on 2017/11/21.
 * app相关设置
 */

public class AppSettingHelper {
    public static Application application;
    private static AppSettingHelper appSettingHelper;
    private static SharedPreferencesHelper sp;
    private static final String APP_SETTING = "AppSetting";
    private static final String IS_OPEN = "isOpen";

    private static final String GESTURES_PASSWORD = "gesturesPassword";//手势密码
    private static final String GESTURES_PASSWORD_IS_OPEN = "gesturesPasswordIsOpen";//手势密码是否开启
    private static final String FINGER_PASSWORD_IS_OPEN = "gesturesPasswordIsOpen";//指纹密码是否开启
    private static final String APP_IS_FIRST_RUN = "APP_IS_FIRST_RUN";//app是否为第一次运行

    public AppSettingHelper(Application application) {
        AppSettingHelper.application = application;
    }

    public static void init(Application application) {
        appSettingHelper = new AppSettingHelper(application);
        sp = new SharedPreferencesHelper(application, application.getPackageName() + APP_SETTING);
    }

    public static void setNotification(boolean isOpen) {
        sp.put(IS_OPEN, isOpen);
    }

    public static boolean getNotification() {
        return (boolean) sp.getSharedPreference(IS_OPEN, true);
    }

    public static String getGestures() {
        return (String) sp.getSharedPreference(GESTURES_PASSWORD, null);
    }

    public static boolean getGesturesIsOpen() {
        return ((boolean) sp.getSharedPreference(GESTURES_PASSWORD_IS_OPEN, false)) &&
                (sp.getSharedPreference(GESTURES_PASSWORD, null) != null);
    }

    public static void setGestures(String gestures) {
        sp.put(GESTURES_PASSWORD, gestures);
    }

    public static void setGesturesIsOpen(boolean gestures) {
        sp.put(GESTURES_PASSWORD_IS_OPEN, gestures);
    }

    public static void setFingerIsOpen(boolean finger) {
        sp.put(FINGER_PASSWORD_IS_OPEN, finger);
    }


    public static boolean getFingerIsOpen() {
        return ((boolean) sp.getSharedPreference(FINGER_PASSWORD_IS_OPEN, false));
    }

    /**
     * 判断是否为第一次运行app
     *
     * @return
     */
    public static boolean isFirstRun() {
        return (boolean) sp.getSharedPreference(APP_IS_FIRST_RUN, true);
    }

    public static void setNotFirstRun() {
        sp.put(APP_IS_FIRST_RUN, false);
    }

}
